import 'package:flutter/widgets.dart';

class DkContainer extends Container {
  final ContainerParam containerParam;

  DkContainer(this.containerParam)
      : super(
          key: containerParam?.key,
          alignment: containerParam?.alignment,
          padding: containerParam?.padding,
          color: containerParam?.color,
          decoration: containerParam?.decoration,
          foregroundDecoration: containerParam?.foregroundDecoration,
          width: containerParam?.width,
          height: containerParam?.height,
          constraints: containerParam?.constraints,
          margin: containerParam?.margin,
          transform: containerParam?.transform,
          child: containerParam?.child,
        );
}

class ContainerParam {
  Key key;
  AlignmentGeometry alignment;
  EdgeInsetsGeometry padding;
  Color color;
  Decoration decoration;
  Decoration foregroundDecoration;
  double width;
  double height;
  BoxConstraints constraints;
  EdgeInsetsGeometry margin;
  Matrix4 transform;
  Widget child;

  ContainerParam.withDefault(
      {this.key,
      this.alignment,
      this.padding,
      this.color,
      this.decoration,
      this.foregroundDecoration,
      this.width,
      this.height,
      this.constraints,
      this.margin,
      this.transform,
      this.child}) {
    if (margin != null && !margin.isNonNegative) {
      margin = null;
    }
    if (padding != null && !padding.isNonNegative) {
      padding = null;
    }
    if (decoration != null && !decoration.debugAssertIsValid()) {
      decoration = null;
    }
    if (constraints != null && !constraints.debugAssertIsValid()) {
      constraints = null;
    }
    if (color != null && decoration != null) {
      decoration = null;
    }
    if (null == child) {
      constraints = null;
    }
  }
}
